package com.citusdata.elven.httpRpc;

import com.citusdata.elven.httpRpc.HttpRpcServer;
import org.apache.http.*;
import org.apache.http.entity.*;
import org.apache.http.protocol.*;
import org.apache.http.util.*;
import org.apache.log4j.Logger;


class HttpRpcShutdownHandler implements HttpRequestHandler {
  private static final Logger logger = Logger.getLogger(HttpRpcShutdownHandler.class);

  private final HttpRpcServer httpServer;

  public HttpRpcShutdownHandler(HttpRpcServer httpServer) {
    this.httpServer = httpServer;
  }

  public void handle(HttpRequest httpRequest, HttpResponse httpResponse, 
                     HttpContext httpContext) {

    logger.info("Received shutdown request");
    httpServer.cancel();
    httpResponse.setStatusCode(HttpStatus.SC_OK);
  }
}
